home *** CD-ROM | disk | FTP | other *** search
/ Aminet 48 / Aminet 48 (2002)(GTI - Schatztruhe)[!][Apr 2002].iso / Aminet / dev / cross / 6502d.lha / comline.c < prev    next >
Encoding:
C/C++ Source or Header  |  2002-01-26  |  2.9 KB  |  64 lines

  1. /*****************************************************************************
  2. * 6502D Version 0.1                                                          *
  3. * Bart Trzynadlowski, 1999                                                   *
  4. *                                                                            *
  5. * Feel free to do whatever you wish with this source code provided that you  *
  6. * understand it is provided "as is" and that the author will not be held     *
  7. * responsible for anything that happens because of this software.            *
  8. *                                                                            *
  9. * comline.c: Function(s) for parsing the command line.                       *
  10. *****************************************************************************/
  11.  
  12. #include <string.h>
  13.  
  14. /*****************************************************************************
  15. * findarg: This function takes 3 arguments: argc, argv[], and args. The      *
  16. * argc argument contains the number of elements in the argv[] pointer array. *
  17. * args contains the string to find. If the string is found then the argument *
  18. * index for the argument following it is returned to the caller, else 0. If  *
  19. * there is no next argument then 0 is returned as well.                      *
  20. *****************************************************************************/
  21. int findarg(int argc, char *argv[], const char *args)
  22. {
  23.         int i;                  
  24.  
  25.         argc--;                 /* account for argv[0]: path name */
  26.         if (argc==0)
  27.         {
  28.                 return 0;       /* no arguments */
  29.         }
  30.  
  31.         for (i=1;i<=argc;i++)   /* start at 1 to avoid argv[0] */
  32.         {
  33.                 if (!strcmp(argv[i], args))     /* if 0 strings are equal */
  34.                         if (i+1<argc+1)        /* is there another arg? */
  35.                                 return i+1;     /* return index */
  36.         }
  37.         return 0;
  38. }
  39.  
  40. /*****************************************************************************
  41. * singlearg: All input is the same as for the above function. This function  *
  42. * differs in that it does not return the _next_ argument after the one the   *
  43. * programmer wants to find but instead returns 1 if the argument specifies   *
  44. * found and 0 if it is not.                                                  *
  45. *****************************************************************************/
  46. int singlearg(int argc, char *argv[], const char *args)
  47. {
  48.         int i;                  
  49.  
  50.         argc--;                 /* account for argv[0]: path name */
  51.         if (argc==0)
  52.         {
  53.                 return 0;       /* no arguments */
  54.         }
  55.  
  56.         for (i=1;i<=argc;i++)   /* start at 1 to avoid argv[0] */
  57.         {
  58.                 if (!strcmp(argv[i], args))     /* if 0 strings are equal */
  59.                         return 1;               /* return index */
  60.         }
  61.         return 0;
  62. }
  63.  
  64.